using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;

namespace MuaDeal
{
    public partial class CapNhatThongTinKhachHang : Form
    {
        public CapNhatThongTinKhachHang()
        {
            InitializeComponent();
        }
        private string tenkh = "";
        DataTable dt = new DataTable();
        public string Tenkh
        {
            get { return tenkh; }
            set { tenkh = value; }
        }
        private void CapNhatThongTinKhachHang_Load(object sender, EventArgs e)
        {
            try
            {

                Datahelper helper = new Datahelper();
                helper.Open();

                SqlCommand comman = new SqlCommand();

                comman.CommandText = "LayThongTinUserTheoMa";
                comman.CommandType = CommandType.StoredProcedure;
                SqlParameter bien1 = comman.Parameters.Add("@tendn", SqlDbType.Char, 30);
                bien1.Direction = ParameterDirection.Input;
                bien1.Value = this.Tenkh;
                
                comman.Connection = helper.Connection;
                SqlDataAdapter adt = new SqlDataAdapter(comman);
                
                adt.Fill(dt);

                helper.Close();
                if (dt.Rows.Count > 0)
                {
                    lbmacty1.Text = dt.Rows[0][0].ToString();
                    lbtenkh1.Text = dt.Rows[0][3].ToString();
                    txtdiachi.Text = dt.Rows[0][5].ToString();
                    txtdienthoai.Text = dt.Rows[0][6].ToString();
                }
            }catch(SqlException ex){}
        }

        private void btncapnhat_Click(object sender, EventArgs e)
        {            
            Datahelper helper = new Datahelper();
            helper.Open();
            //SqlTransaction sqltran = helper.Connection.BeginTransaction();
            SqlCommand comman = new SqlCommand();
            //comman.Transaction = sqltran;
            comman.CommandText = "sp_Capnhatthongtinuser";
            comman.CommandType = CommandType.StoredProcedure;

            SqlParameter bien1 = comman.Parameters.Add("@tenus", SqlDbType.Char, 30);
            bien1.Direction = ParameterDirection.Input;
            bien1.Value = this.Tenkh;

            SqlParameter bien2 = comman.Parameters.Add("@dt", SqlDbType.Char, 20);
            bien2.Direction = ParameterDirection.Input;
            bien2.Value = txtdienthoai.Text;

            SqlParameter bien3 = comman.Parameters.Add("@dc", SqlDbType.NVarChar, 100);
            bien3.Direction = ParameterDirection.Input;
            bien3.Value = txtdiachi.Text;
            comman.Connection = helper.Connection;

            int kq = 0;
            kq = comman.ExecuteNonQuery();
            //sqltran.Rollback();
           
        }
    }
}